#include <iostream>
#include <unordered_map>

using namespace std;

struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

unordered_map<long long, int > cnt;


int dfs(TreeNode* root, long long cur, int targetSum)
{
    if (root == nullptr)
        return 0;
    int ans = 0;
    cur += root->val;
    if (cnt.find(cur - targetSum) != cnt.end()) ans += cnt[cur - targetSum];
    cnt[cur]++;
    ans += dfs(root->left, cur, targetSum);
    ans += dfs(root->right, cur, targetSum);
    cnt[cur]--;

    return ans;
}


int pathSum(TreeNode* root, int targetSum) {

    cnt[0] = 1;
    return dfs(root, 0, targetSum);
}

int main()
{

	return 0;
}